<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
	</body>
	<script type="text/javascript">
		
		window.onload = () => {
			getMessage(1,"https://api.apiopen.top/getWangYiNews","page=1&count=2");
			getMessage(0,"http://poetry.apiopen.top/poetryFull","?count=2&page=1");
		}
		
		/**
		 * @getMessage 方法
		 * @param {Number} state 0 表示 get, 1 表示 post
		 * @param {String} url 地址
		 * @param {String} word 传入参数
		 */
		function getMessage (state,url,word) {
			if(url == "" || url == null || url.length == 0){ alert("数据有误"); return; }
			
			var trans = "", word1 = "", word2 = "";
			if (state == 0){ trans = "get"; word1 = word; }
			if (state == 1) { trans = "post"; word2 = word; }
			
			var ajax = new XMLHttpRequest();
			ajax.open(trans,url + word1);
			// var a = "province=福建&city=龍岩&conty=新罗区";
			ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			ajax.send(word2);
			ajax.onreadystatechange = () => {
				if (ajax.status == 200 && ajax.readyState == 4) {
					if(typeof(ajax.responseText) == 'string'){
						var obj = JSON.parse(ajax.responseText);
						console.log(obj);
					}else{
						console.log("数据出错，请重新尝试");
					}
				}
			}
		}
		
	</script>
</html>
